import { createSlice } from "@reduxjs/toolkit"
import type { IReceptionItem } from "../interface/IlistItem"

// 片区一
const userSlice = createSlice({
    // 片区,使用时解构片区
    name: "user",
    // 片区初始状态  新增接待项目片区
    initialState: {
        newReceiptionItem: {
            LikeAndDislike: [],
            accompany: '',
            applier: '',
            billNo: '',
            companyName: '',
            costCenter: '',
            dateFrom:0,
            dateTo:0,
            itemMaker: '',
            location: [],
            receiveType: '',
            taskBody: '',
            vehicles: '',
            visitNum: 1,
            visitPurpose: '',
        } as IReceptionItem,
        step: 1,
    },
    // 片区操作
    reducers: {
        setUserInfo(state, action) {
            state.newReceiptionItem = action.payload;
        },
        setStep(state, action) {
            state.step = action.payload
        },
        addCareness(state, action) {
            state.newReceiptionItem = { ...state.newReceiptionItem, LikeAndDislike: [action.payload, ...state.newReceiptionItem.LikeAndDislike] }
        },
        delCareness(state, action) {
            state.newReceiptionItem = { ...state.newReceiptionItem, LikeAndDislike: state.newReceiptionItem.LikeAndDislike.filter(item => item.id !== action.payload) }
        },
        reset(state) {
            state.newReceiptionItem = {
                LikeAndDislike: [],
                accompany: 'string',
                applier: 'string',
                billNo: '',
                companyName: '',
                costCenter: '',
                dateFrom: '',
                dateTo: '',
                itemMaker: '',
                location: [],
                receiveType: '',
                taskBody: '',
                vehicles: '',
                visitNum: '',
                visitPurpose: '',
            }
    }
}
});
export const { setUserInfo, setStep, addCareness, delCareness,  reset} = userSlice.actions;
export default userSlice;